package com.zhang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhang.entity.ShoppingSysCustomer;
import com.zhang.mapper.ShoppingSysCustomerMapper;
import com.zhang.service.ShoppingSysCustomerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhang.units.LoginUnits;
import com.zhang.units.Result;
import com.zhang.vo.CustomerLoginVo;
import com.zhang.vo.RegisterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZhangD
 * @since 2021-07-13
 */
@Service
public class ShoppingSysCustomerServiceImpl extends ServiceImpl<ShoppingSysCustomerMapper, ShoppingSysCustomer> implements ShoppingSysCustomerService {

    @Autowired
    private ShoppingSysCustomerMapper shoppingSysCustomerMapper;

    @Override
    public LoginUnits login(CustomerLoginVo customerLoginVo) {
        CustomerLoginVo user= shoppingSysCustomerMapper.login(customerLoginVo);
        if (user == null){
            return LoginUnits.setMsg("用户名或密码不正确");
        }else {
            return LoginUnits.setDetail(user,true);
        }

    }

    @Override
    public LoginUnits preregist(CustomerLoginVo customerLoginVo) {
        CustomerLoginVo user= shoppingSysCustomerMapper.preRegist(customerLoginVo);
        if (user!=null){
            return LoginUnits.setMsg("用户名已经存在");
        }else {
            return LoginUnits.setSuccess(true,"请继续录入信息");
        }
    }

    @Override
    public LoginUnits regist(RegisterVo registerVo) {
        ShoppingSysCustomer customer = new ShoppingSysCustomer();
        customer.setLoginName(registerVo.getLoginName());
        customer.setUsername(registerVo.getUsername());
        customer.setPassword(registerVo.getPassword());
        customer.setAddress(registerVo.getAddress());
        customer.setAge(registerVo.getAge());
        customer.setEmail(registerVo.getEmail());
        customer.setMobile(registerVo.getMobile());
        int insert = shoppingSysCustomerMapper.insert(customer);

        return LoginUnits.setDetail(insert,true);
    }
}
